import { Injectable } from '@nestjs/common'
import { InjectModel } from '@nestjs/mongoose'
import { Printer } from './printer.schema'
import { Model } from 'mongoose'

@Injectable()
export class PrinterService {

    // 模型注入
    constructor(@InjectModel(Printer.name) private PrinterSchema: Model<Printer>) {
    }
    //添加打印机
    async addPrinter(body: any) {
        console.log(body)
        await this.PrinterSchema.create(body)
        return "添加成功" 
    }
    //查询打印机
    async getPrinter(searchList:any[]) {
        let data
        if (searchList.length > 0) {
            data = await this.PrinterSchema.find({ $and: searchList }) // 使用

        } else {
            data = await this.PrinterSchema.find() // 使用
        }

        return data
    } 
    //修改打印机  
    async updatePrinter(body: any) {
        await this.PrinterSchema.updateOne({ _id: body._id }, body)
        return  "修改成功"
    }
    //删除打印机
    async deletePrinter(body: any) {
        await this.PrinterSchema.deleteOne({ _id: body._id })
        return "删除成功"
    }

    
}